# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
using("SideMenu_Open.air")
import SideMenu_Open
        
class SideMenu_Feedback(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))

        problemContent = "来自自动化测试的反馈，请忽视"
        phoneNum = "13800138000"

        if "problemContent" in args:
            problemContent = args["problemContent"]

        if "phoneNum" in args:
            phoneNum = args["phoneNum"]
        

        # 打开左侧菜单
        isOpenSideMenu = SideMenu_Open.runTest({})
        if not isOpenSideMenu:
            return False

        # 获取左侧菜单节点
        bottomPanel = poco("bottom_panel")
        if not bottomPanel.exists():
            return False

        btnFeedback = bottomPanel.offspring("feedback_btn")
        if not btnFeedback.exists():
            return False

        self.clickButton(btnFeedback)

        try:
            poco("HelpFeedbackLayer").wait_for_appearance()
        except:
            assert(True, True, "反馈面板正常弹出")
            return False
        
        feedbackLayer = poco("HelpFeedbackLayer")
        btnAddFeedback = feedbackLayer.offspring("button_feedback")
        self.clickButton(btnAddFeedback)

        try:
            poco("AdviseFeedbackLayer").wait_for_appearance()
        except:
            assert(True, True, "反馈面板正常弹出")
            return False

        adviseFeedbackLayer = poco("AdviseFeedbackLayer")
        txtProblem = adviseFeedbackLayer.offspring("input_problem")
        self.clickButton(txtProblem)
        text(problemContent)

        txtPhone  = adviseFeedbackLayer.offspring("input_contact")
        self.clickButton(txtPhone);
        text(phoneNum)

        btnFeedbackType = adviseFeedbackLayer.offspring("problem_btn")
        self.clickButton(btnFeedbackType)

        try:
            poco("ProblemClassifyLayer").wait_for_appearance()
        except:
            assert(True, True, "反馈面板正常弹出")
            return False

        problemTypeLayer = adviseFeedbackLayer.offspring("ProblemClassifyLayer")
        lobbyProblem1 = problemTypeLayer.offspring("lobby_problem1")
        btnProblem = lobbyProblem1.child("btn_problem")
        self.clickButton(btnProblem)

        btnSend = adviseFeedbackLayer.offspring("btn_send")
        if not btnSend.exists():
            return False
        
        self.clickButton(btnSend)

        sleep(1.0) # 等待发送反馈完成

        btnFinish = adviseFeedbackLayer.offspring("btn_finish")
        self.clickButton(btnFinish)

        btnClose = feedbackLayer.offspring("close_btn")
        self.clickButton(btnClose)

        sleep(1.0)

        poco.click([0.7, 0.5])

        return True
        
_instance = SideMenu_Feedback()
runTest = _instance.runTest